package ooday04;
/**
 * @author Pxl
 */
public class Test {
    public static void main(String[] args) {
        Dog[]dog=new Dog[2];
        Fish[]fish=new Fish[1];
        Chick[]chick=new Chick[1];
        dog[0]= new Dog("中华田园犬","大黄",7,"公");
        dog[1]= new Dog("边牧","妮妮",4,"母");
        dog[1].age=6;
        dog[0].name="追风";
        for(int i =0;i<dog.length;i++){
            dog[i].eat();
            dog[i].swim();
            dog[i].sleep();
            dog[i].lookHome();
        }

        fish[0]=new Fish("敖甲",500,"公");
        fish[0].eat();
        fish[0].swim();
        fish[0].sleep();

        chick[0]=new Chick("坤坤",12,"母");
        chick[0].eat();
        chick[0].layEgg();
        chick[0].sleep();


        Animal[]animals=new Animal[5];
        animals[0]=new Dog("德牧","啸天",6,"公");
        animals[1]=new Dog("杜宾","莉莉丝",4,"母");
        animals[2]=new Fish("大金",2,"公");
        animals[3]=new Fish("小花",1,"母");
        animals[4]=new Chick("金鹏",10,"母");
        for(int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].sleep();

            if(animals[i] instanceof Dog){
                Dog dog1 =(Dog) animals[i];
                dog1.swim();
                dog1.lookHome();
            }
            if(animals[i] instanceof Fish){
                Fish fish1=(Fish) animals[i];
                fish1.swim();
            }
            if(animals[i] instanceof Chick){
                Chick chick1=(Chick) animals[i];
                chick1.layEgg();
            }
        }
        Animal o =new Dog("斑点狗","知识点",7,"母");
        //引用o的对象，就是Dog类型
        Dog d =(Dog) o;
        //引用O的对象，实现了Swim接口
        Swim s=(Swim) o;


        /*多态的运用2：
        Master master=new Master();
        Dog dog1=new Dog("挪威纳","卷卷",2,"母");
        Fish fish1=new Fish("大头",6,"公");
        Chick chick1=new Chick("金鼎",5,"公");
        master.feed(dog1);
        master.feed(fish1);
        master.feed(chick1);

         */

    }
}
